<template>
  <div class="app-container">
    <div class="grid-container">
      <el-row class="grid-table-tool">
        <el-col :span="24" class="tool-action">
          <el-input v-model="params.key" placeholder="请输入关键词" @keyup.enter="handleSearch" style="width:300px;margin-right:10px;"></el-input>

          <el-button type="primary" icon="el-icon-search" v-waves @click="handleSearch">查询</el-button>
          <el-button type="success" icon="el-icon-circle-plus-outline"  @click="handleAdd" >新增</el-button>
        </el-col>
      </el-row>
      <el-table :data="resp.dataList" border class="grid-table" height="100px" v-el-height-adaptive-table="{bottomOffset: 55}" width="100%" v-loading="loading">
        <el-table-column type="selection" width="40" align="center"> </el-table-column>
        ## for(item in entity.generalList) {
          ## if(item.isId == true){continue;}
          ## if(item.name == "deleted" ){continue;}
          ## if(item.name == "createAt" ){continue;}
          ## if(item.name == "creatorId" ){continue;}
          ## if(item.name == "modifyAt" ){continue;}
          ## if(item.name == "modifierId" ){continue;}
          <el-table-column prop="${item.name}" label="${item.displayName}" align="center"></el-table-column>
        ## }
        <el-table-column label="操作" width="150" fixed="right">
          <template slot-scope="scope">
            <el-button type="success" size="mini" plain @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <disable name="删除" :rowId="scope.row.id.toString()" @emit="handleDelete"></disable>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="params.page" :limit.sync="params.pageSize" @pagination="init"></pagination>
    </div>
  </div>
</template>
<script>
  import {findList,deleteOne} from "../../api/${entity.code}";
  import Disable from "@/components/Disable";
  import Pagination from '@/components/Pagination'

  export default {
    name:"${entity.name}List",
    components:{Disable, Pagination},
    data(){
      return{
        resp:{
          dataList:[],
          total:0,
        },
        params: {
          key:null,
          page: 1, pageSize: 10,
          order: null, sort: null
        },
        pageSizes:[10,20,30],
        loading:false,
      }
    },
    methods:{
      handleAdd(){
        this.$router.push({name: '${entity.name}Detail'})
      },
      handleEdit(index,row){
        this.$router.push({name: '${entity.name}Detail',query:{id:row.id}})
      },
      async handleDelete(id,name) {
        this.loading = true;
        if(name == '删除') {
          let data = { id:id, }
          let resp = await deleteOne(data)
          this.loading = false;
          if(this.qUtil.validResp(resp)) {
            this.$message.success('删除成功!');
            if(this.resp.dataList.length===1 && this.params.page>1){
              this.params.page--;
            }
            this.init();
          } else this.$message.warning(resp.msg||'删除失败');
        }
      },
      handleSearch(){
        this.params.page = 1;
        this.init();
      },
      async init(){
        this.loading = true;
        let resp = await findList(this.params);
        this.loading = false;
        if(this.qUtil.validResp(resp)){
          this.resp = resp.data;
        }
      }
    },
    mounted(){
      this.init();
    }
  }
</script>
<style>
  .web-user-list .el-table,.web-user-list .el-table th{ text-align: center; }
</style>
